<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<meta content="yes" name="apple-mobile-web-app-capable" />
		<meta content="black" name="apple-mobile-web-app-status-bar-style" />
		<meta content="telephone=no" name="format-detection" />
		<meta content="email=no" name="format-detection" />
		<title>巡检结果</title>
		<link rel="stylesheet" href="../../css/s_plus.css" />
		<link rel="stylesheet" href="../../css/base.css" />
		<link rel="stylesheet" href="../../css/layout.css" />
		<link rel="stylesheet" href="../../css/hui.css" />

		<link rel="stylesheet" href="../../css/choice.css" />
		<script type="text/javascript" src="../../libs/vue.js"></script>
		<script type="text/javascript" src="../../js/jquery.1.9.1.min.js"></script>
		<script type="text/javascript" src="../../js/app/url.js"></script>
		<script type="text/javascript" src="../../libs/hui.js"></script>
		<script type="text/javascript" src="../../js/app/api.js"></script>
		<script type="text/javascript" src="../../js/control/pop.js"></script>
		<script type="text/javascript" src="../../js/md5.js"></script>
		<script type="text/javascript" src="../../js/control/swal/sweetalert.min.js"></script>
		<link rel="stylesheet" href="../../js/control/swal/sweetalert.css" />
		

	</head>

	<body>
		<div id="wrapper">
			<header class="f_l maxbox subhead">
				<a class="back" @click="back"><i class="iconfont">&#xe605;</i></a>
				<h1>巡检结果</h1>
				<a class="f_r arrow_r" href="javascript:void(0);" v-if="type=='normal'"><i class="iconfont">&#xe611;</i></a>
				<!--<ul class="head_nav">
    <li><a @click="gisMap">地图模式</a></li>
    <li><a @click="ins_list">列表模式</a></li>
  </ul>-->
			</header>

			<section class="f_l maxbox edit_list">


				<ul>
					<li>
						<b>{{title}}</b>
						
						
						
						<p v-if="checkType==0">
														已完成 <span class="red" >{{resTerminal_checked}}</span> 终端数 <span class="red">{{resTerminal_number}}</span>

								
						</p>
						<p v-if="checkType==1">
								已完成 <span class="red" >{{resTerminal_checked}}</span>	 抽检数 <span class="red">{{checkCount}}</span> 终端数 <span class="red">{{resTerminal_number}}</span>
							</p>
					</li>
					<!--<li>
      <b>巡检任务</b>
      <p>终端数 <span class="red">{{resTerminal_number}}</span> 个</p>
    </li>-->
				</ul>

			</section>
			<section class="f_l maxbox block">
				<dl>
					<dt>
      <h2>基础信息</h2>
    </dt>
					<dd class="txt_list">
						<p><em>标题：</em>{{task.name}}</p>
						<p><em>处理状态：</em><span class="mar_r green">{{showState(task.state)}}</span></p>
						<p><em>巡检种类：</em>{{showType(task.type)}}</p>
						<p><em>时间：</em>{{formatTime(task.startTime)}} ~ {{formatTime(task.endTime)}}</p>
					</dd>
				</dl>
			</section>
			<section class="f_l maxbox block mar_t">
				<dl>
					<dt>
      <h2>终端信息</h2>
    </dt>

					<!--<section >-->

						<dd class="txt_list f_l img_list"  v-for="item in lists">
							<p><em>设备编号：</em>{{item.termimalCode}}</p>
							<p><em>工程地址：</em>{{item.belongStreet}}</p>
							<p><em>告警状态：</em>{{showStatus(item.status)}}</p>
							<!--<p v-if="item.remarks"><em>描述：</em>{{item.remarks}}</p>-->

								<!--<span class="mar_r orange">异常</span>-->
	<p><em>设备状态：</em><span v-bind:class="[activeClass, infoClass(item.checkStatus)]">{{showCheckStatus(item.checkStatus)}}</span>
								<!--v-bind:class="[activeClass, errorClass]"-->
								<!--<span class="mar_r orange">异常</span>-->
															<p><em></em>&nbsp;</p>

	<ul v-if="item.imgUrl!=''">
															<!--<li><img src="../../images/map.jpg" alt="" /></li>-->

								<li class="imgs" @click="showImg($event)" v-for="it in  cutImgs(item.imgUrl)"><img :src="it" /></li>
							</ul>
							

						</dd>
						<!--<dd class="f_l img_list" style="margin-top:-20px;">
						
						</dd>-->

					<!--</section>-->
					<!--<dd class="txt_list">
      <p><em>设备编号：</em>4546332163</p>
      <p><em>工程地址：</em>成都市武侯区高朋大道11号附近</p>	
      <p><em>作业状态：</em><span class="mar_r red">未完成</span></p>
    </dd>
    <dd class="f_l img_list" style="margin-top:-20px;">
      <ul>
        <li><img src="../../images/map.jpg" alt="" /></li>
        <li><img src="../../images/map.jpg" alt="" /></li>
      </ul>
    </dd>
    <dd class="txt_list">
      <p><em>设备编号：</em>4546332163</p>
      <p><em>工程地址：</em>成都市武侯区高朋大道11号附近</p>	
      <p><em>作业状态：</em><span class="mar_r green">完成</span><span class="mar_r green">正常</span></p>
    </dd>-->
				</dl>
			</section>

			<section class="f_l maxbox block_two ">
				<div style="text-align: center;">
						
				
						 <a v-if="task.state !='2'" @click="go" class="btn minor_btn">处理巡检</a>
						
					<a v-if="task.state !='2'" @click="finish" class="btn mian_btn">完成巡检</a>
			
				
					
				</div>
				<div>
					<p>&nbsp;</p>
				</div>
			</section>
		</div>
		
			<!-- 以下为 phoneSwipe 插件 dom 复制即可 -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="pswp__bg"></div>
    <div class="pswp__scroll-wrap">
        <div class="pswp__container" style="overflow:visible;">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>
        <div class="pswp__ui pswp__ui--hidden">
            <div class="pswp__top-bar">
                <div class="pswp__counter"></div>
                <button class="pswp__button pswp__button--close" title="关闭"></button>
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                      <div class="pswp__preloader__cut">
                        <div class="pswp__preloader__donut"></div>
                      </div>
                    </div>
                </div>
            </div>
            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div> 
            </div>
            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>
        </div>
    </div>
</div>
<link rel="stylesheet" href="../../js/control/phoneswipe/photoswipe.css" type="text/css" />
		<script type="text/javascript" src="../../js/control/phoneswipe/photoswipe.min.js" ></script>
		<script type="text/javascript" src="../../js/control/phoneswipe/photoswipe-ui-default.min.js" ></script>
		<script>
			
			function refresh(){
				console.log('返回刷新加载数据');
				loadDetail();
			}
			
				function previewImg(index){
					var pswpElement = document.querySelectorAll('.pswp')[0];
					var items = [];
					//获取图片数据并填充近数组
					hui('.imgs').each(function(eimg){
						var imgObj = {src:eimg.getAttribute('src'), w:eimg.naturalWidth, h:eimg.naturalHeight};
						items.push(imgObj);
					});
					var options = {index: index};
					var gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);
					gallery.init();
				}
			
			$(function() {
				
				
			

				//头部点击显示与隐藏
				$(".arrow_r").click(function() {
					//		$(".head_nav").toggle();
					var taskId = localStorage.getItem("taskId");

					localStorage.setItem("taskId", taskId);
					console.log("要传的值: taskId " + taskId);
					hui.open("inspection_map.html?time="+apiManage.getNow(), {}, true, {});
				});

			});

			loadDetail();

			function loadDetail() {
				hui.loading("");
				var taskId = localStorage.getItem("taskId");

				var username = localStorage.getItem("username");
				var sec = localStorage.getItem("sec_pwd");
				var time = apiManage.getNow();
				var key = "loginName=" + username + "&passWord=" + sec + "&time=" + time;
				var paramKey = hex_md5(key);
				var jsonParam = JSON.stringify({
					loginName: username,
					time: time,
					key: paramKey
				});
				console.log("jsonParam:  " + jsonParam);

				var path = urlManager.inspection_detail() + "?taskId=" + taskId;
				console.log("path:  " + path);
				$.ajax({
					type: "GET",
					url: path,
					beforeSend: function(request) {
						request.setRequestHeader("loginName", username);
						request.setRequestHeader("time", time);
						request.setRequestHeader("sign", paramKey);
						request.setRequestHeader("Content-Type", "application/text");

					},
					success: function(result) {
						hui.closeLoading();
						console.log("任务详情:" + JSON.stringify(result));


					console.log("checkType--"+result.checkType);
					console.log("checkCount--"+result.checkCount);

						//			    $(".work_list").show();
						if(result != null) {
							sp.resTerminal_checked = result.resTerminal_checked;
							sp.resTerminal_number = result.resTerminal_number;

						if(result.checkType){
							
							if(result.checkType=='0'){
								sp.title= "全检";
							}
							else{
								sp.title= "抽检";
							}
							sp.checkType=parseInt(result.checkType);
						}
						if(result.checkCount){
									sp.checkCount=parseInt(result.checkCount);

							}
							sp.task = result.checkTask;
							sp.lists = result.resTerminals;
						}

					}

				});

			}

			//zdList();

			var sp = new Vue({
				el: "#wrapper",
				data: {
					title:"",
					activeClass:"",
					type:"",
					task: {},
					lists: [],
					resTerminal_number: "",
					resTerminal_checked: "",
					checkType:0,
					checkCount:0

				},
				mounted: function() {
					var type=localStorage.getItem("type");
					this.type=type;
				},
				methods: {
			
			
					showImg:function(e){
						  var index = $(e.currentTarget).index();
			    		previewImg(index);
					},
					infoClass:function(param){
						
						if(param=='0'){
							return "red";
						}
						else if(param=='1'){
							return "green";

						}
						else{
							return "orange";
						}
					},
					cutImgs:function(imgUrl){
						if(imgUrl!=null&&imgUrl!=''){
							return imgUrl.split(",");
						}
					},
					finish: function() {
						finishTask();

					},
					go: function() {
						var taskId = localStorage.getItem("taskId");
						localStorage.setItem("taskId", taskId);
						hui.open("track_task.html?time="+apiManage.getNow(), {}, true, {});
					},
					back: function() {
						hui.back();

					},

					showCheckStatus: function(status) {
						//							0异常 1正常2未打卡
						if(status == '0') {
							return "异常";
						} else if(status == '1') {
							return "正常";
						} else if(status == '2') {
							return "未打卡";
						} else {
							return "";

						}
					},
					showStatus: function(status) {

						if(status == '0') {
							return "无告警	";
						} else if(status == '1') {
							return "一般告警";
						} else if(status == '2') {
							return "严重告警";
						} else {
							return "工单处理";

						}
					},
					gisMap: function() {

					},

					geshi: function(param) {
						return formatTime(param);
					},
					showType: function(param) {
						//							0：日巡检 1：周巡检 2：月巡检
						if(param == '0') {
							return "日巡检";
						} else if(param == '1') {
							return "周巡检 ";
						} else {
							return "月巡检";

						}
					},
					showState: function(param) {
						//								0下发 1接收 2处理
						if(param == '0') {
							return "下发";
						} else if(param == '1') {
							return "接收";
						} else {
							return "处理";

						}
					},

					show: function(zdCode) {
							localStorage.setItem("zdCode", zdCode);
							hui.open("alerm_show.html?time" + apiManage.getNow(), {}, true, {});
						}

						,
					ins_list: function() {
						hui.open("inspection_list.html", {}, true, {});
					}

				}

			});

			//完成巡检
			function finishTask() {
				
				var alertTitle = "";
				if(sp.checkType=='1'){
					if(sp.checkCount>sp.resTerminal_checked){
//						alert("抽检数为:"+sp.checkCount+",已完成为:"+sp.resTerminal_checked+",不能完成巡检任务！");
//						swal("暂不能完成巡检任务", "抽检数为:"+sp.checkCount+",  已完成:"+sp.resTerminal_checked+" 个终端巡检", "error");
						alertTitle = "抽检数为:"+sp.checkCount+",  已完成:"+sp.resTerminal_checked+" 个";
//						return;
					}
					else{
						alertTitle = "抽检数为:"+sp.checkCount+",  已完成:"+sp.resTerminal_checked;
					}
				}
				else{
					if(sp.resTerminal_checked<sp.resTerminal_number){
						alertTitle = "已完成:"+sp.resTerminal_checked+",  终端数:"+sp.resTerminal_number+" 个";
						swal("必须完成所有巡检",alertTitle, "warning");

						return;
								
					}
				}
				

				var taskId = localStorage.getItem("taskId");
				var username = localStorage.getItem("username");
				var sec = localStorage.getItem("sec_pwd");
				var time = apiManage.getNow();
				var key = "loginName=" + username + "&passWord=" + sec + "&time=" + time;
				var paramKey = hex_md5(key);
				var jsonParam = JSON.stringify({
					loginName: username,
					time: time,
					key: paramKey
				});
				console.log("jsonParam:  " + jsonParam);

				var path = urlManager.inspection_Finish() + "?taskId=" + taskId;
				console.log("path:  " + path);
//				<p>已完成 <span class="red">{{resTerminal_checked}}</span> 终端数 <span class="red">{{resTerminal_number}}</span></p>
				
				
				
				var sx=sp.resTerminal_number-sp.resTerminal_checked;
					swal({  
								title: "确定要完成巡检么?",
								  text: alertTitle,
								  type: "warning",
								  showCancelButton: true,
								  confirmButtonColor: "#DD6B55",
								  confirmButtonText: "确认",
								  cancelButtonText: "取消",
								  closeOnConfirm: true,
								  closeOnCancel: true
							},
							function(isConfirm) {  
								if(isConfirm) {
//									hui.open("inspection_list.html?time" + apiManage.getNow(), {}, true, {});  
//								  alert('点了确认');
//								  return;

//								return;
								  
												  	
								$.ajax({
									type: "GET",
									url: path,
									beforeSend: function(request) {
										request.setRequestHeader("loginName", username);
										request.setRequestHeader("time", time);
										request.setRequestHeader("sign", paramKey);
										request.setRequestHeader("Content-Type", "application/text");
									},
									success: function(result) {
										console.log("巡检已完成 :  " + JSON.stringify(result));
				
										swal({  
												title:"巡检已完成",
												  text: "",
												  type: "success",
												  showCancelButton: false,
												  confirmButtonColor: "#DD6B55",
												  confirmButtonText: "确认",
												  cancelButtonText: "取消",
												  closeOnConfirm: true,
												  closeOnCancel: false
											},
											function(isConfirm) {  
												if(isConfirm) {
														//console.log("提交执行到这里了");
//														return;
//													hui.open("inspection_list.html?time" + apiManage.getNow(), {}, true, {});  
				
											loadDetail();
				
												} else { 
													console.log("提交取消");
				
													 }
											});
				
									}
				
								});
								
								
							
				
								  
								} else { 
//									 alert('点了取消');
//									return;
							}
							});


				
			
			}

			Date.prototype.format = function(format) //author: meizz
			{
				var o = {
					"M+": this.getMonth() + 1, //month
					"d+": this.getDate(), //day
					"h+": this.getHours(), //hour
					"m+": this.getMinutes(), //minute
					"s+": this.getSeconds(), //second
					"q+": Math.floor((this.getMonth() + 3) / 3), //quarter
					"S": this.getMilliseconds() //millisecond
				}
				if(/(y+)/.test(format)) format = format.replace(RegExp.$1,
					(this.getFullYear() + "").substr(4 - RegExp.$1.length));
				for(var k in o)
					if(new RegExp("(" + k + ")").test(format))
						format = format.replace(RegExp.$1,
							RegExp.$1.length == 1 ? o[k] :
							("00" + o[k]).substr(("" + o[k]).length));
				return format;
			}

			function formatTime(val) {
				if(val == null || val == '') {
					return "";
				}
				var re = /-?\d+/;
				var m = re.exec(val);
				//	         m = m.replace(/\-/g, "/");
				var d = new Date(parseInt(m[0]));

				// 按【2012-02-13 09:09:09】的格式返回日期
				//	        var tmp  = d.format("yyyy-MM-dd hh:mm:ss");
				//	        console.log("格式化时间:   "+tmp);
				return d.format("yyyy-MM-dd hh:mm:ss");
			}
		</script>

	</body>

</html>